package com.zhhh;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
/*import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletRegistrationBean;*/
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import com.alibaba.druid.support.http.StatViewServlet;
import com.zhhh.filter.CorsFilter;
import com.zhhh.servlet.DocUploadConvertServlet;

/**
 * Spring-Boot启动类
 * 
 */
//@Configuration
//@EnableAutoConfiguration
//jpa使用自定义加载工厂
//@EnableJpaRepositories(basePackages = { "com.zhhh.repository" })
//@EnableJpaRepositories(repositoryFactoryBeanClass = BaseRepositoryFactoryBean.class)
@SpringBootApplication
//@ComponentScan(basePackages = {"com.hl001.*","com.zhhh.*"})
//@MapperScan(basePackages = {"com.hl001.**.mapper","com.zhhh.**.mapper"})
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class);
	}

	@Bean
	public FilterRegistrationBean<CorsFilter> registrationBean() {
		FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<CorsFilter>();
		bean.addUrlPatterns("/*");
		bean.setFilter(new CorsFilter());
		return bean;
	}

	// 注册servlet
	@Bean
	public ServletRegistrationBean<DocUploadConvertServlet> uploadServlet() {
		ServletRegistrationBean<DocUploadConvertServlet> registrationBean = new ServletRegistrationBean<DocUploadConvertServlet>();
		registrationBean.setServlet(new DocUploadConvertServlet());
		registrationBean.addUrlMappings("/upload");
		return registrationBean;
	}

	@Bean
	public ServletRegistrationBean<StatViewServlet> druidStatViewServlet() {
		ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>(new StatViewServlet(),
				"/druid/*");
		registrationBean.addInitParameter("allow", "127.0.0.1");// IP白名单 (没有配置或者为空，则允许所有访问)
		registrationBean.addInitParameter("deny", "");// IP黑名单 (存在共同时，deny优先于allow)
		registrationBean.addInitParameter("loginUsername", "root");
		registrationBean.addInitParameter("loginPassword", "root");
		registrationBean.addInitParameter("resetEnable", "false");
		return registrationBean;
	}

}
